﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HotelManagement.Class;

namespace HotelManagement.UserManagementModule
{
    public partial class CreateAccountForStaff1 : System.Web.UI.Page
    {
        Staff stf;
        protected void Page_Load(object sender, EventArgs e)
        {
            UserAccount us=(UserAccount)Session["object"];
            Label3.Text = us.FirstName + " " + us.LastName; //heading
            stf = (Staff)Session["staff"];
            Label4.Text = stf.FirstName + " " + stf.LastName; //staff name
            TextBox1.Text = stf.StaffID;
            TextBox2.Text = stf.FirstName;
            TextBox3.Text = stf.LastName;
            TextBox4.Text = stf.EmailAddress;
            TextBox5.Text = stf.DutyType;
            
        }

        protected void Button4_Click(object sender, EventArgs e) //create account button
        {
            string username = TextBox6.Text; //username
            string password = TextBox7.Text; //password
            int result = HotelDBManager.createStaffAccount(stf, username, password);
            if ( result== 1) { //insert success
                Response.Redirect("~/UserManagementModule/CreateAccountSuccess.aspx");
            }
            else if(result==2){ //pk violation
                Label9.Text="User Name already Exists! Please choose other names!";
                Label9.Visible=true;
            }
            else{ //update fail
                Label1.Visible=true;
            }
        }
    }
}